﻿var app = new Vue({
	el: '#app',
	extends: isLogin,
	components: {
		headers: header,
		navs: nav,
		footers: footer,
		login: login,
	},
	data: {
		bgImg: 'img/PCindex/top1.jpg',
		bannerData: '', //轮播图
		navState: '增值空间',
		testData: '', //考试信息数据
		trainData: '', //培训信息数据
		testClass: '建造师/建筑师', //考试分类
		testClassArr: ['建造师/建筑师', '勘察设计', '造价师/造价员', '监理师/监理从业人员', '质量/安全/检测', '房地产/土地/规划', '其他'], //考试分类的数组
        trainClassArr: ['三类人员', '执业资格考试', '科教培训', '质量检测人员', '执业资格继续教育', '造价员','广东省九大员','特种作业证','岗位技能证'], //培训分类的数组 '小型工程项目负责人'//已经没有
		trainClass: '三类人员' //培训分类
	},
	methods: {
		//header组件的搜索方法
		searchHeader: function(searchCtx) {

		},
		showBuildingModal:function(){
			xq.toast();
		},
		//Top宣传
		getBanner: function() {
			var _this = this;
			var method = 'EduTrain/GetPageTop';
			var param = {
				PageSize: 5,
				PageIndex: 0
			};
			xq.getUrl(method, param, function(res) {
				if(res.data) {
					var data = res.data;
					for(var i = 0; i < data.length; i++) {
						if(data[i].PicUrl) {
							if(data[i].PicUrl.indexOf('http://') == -1) {
								data[i].PicUrl = xq.httpUrl + data[i].PicUrl;
							}
						}
					}
					_this.bannerData = data;
					Vue.nextTick(function() {
						var swiper = new Swiper('.swiper-container', {
							pagination: '.swiper-pagination',
							autoplay: 3000,
							onSlideChangeStart: function(swiper) {
								$(".imgNav li").eq(swiper.activeIndex).addClass("cur").siblings("li").removeClass("cur");
							}
						});
						$(".imgNav li").mouseenter(function() {
							var index = $(this).index();
							swiper.slideTo(index)
							$(this).addClass("cur").siblings("li").removeClass("cur");
						})
					});
				}
			})
		},
		//获取考试信息
		getTestInfo: function() {
			var _this = this;
			var method = 'EduTrain/GetPageExam';
			var param = {
				Class: this.testClass
			};
			xq.getUrl(method, param, function(res) {
				if(res.data) {
					var data = res.data;
					for(var i = 0; i < data.length; i++) {
						//						data[i].TrainStartDate = xq.getYMDHM(data[i].TrainStartDate,'yy/mm/dd');
						data[i].OldDate = xq.getYMDHM(data[i].OldDate, 'yy/mm/dd');
					}
					_this.testData = data;
				}
			})
		},
		//获取培训信息
		getTrainInfo: function() {
			var _this = this;
			var method = 'EduTrain/GetPageTrain';
			var param = {
				Class: this.trainClass
			};
			xq.getUrl(method, param, function(res) {
				if(res.data.length > 0) {
					var data = res.data;
					for(var i = 0; i < data.length; i++) {
						//						data[i].TrainStartDate = xq.getYMDHM(data[i].TrainStartDate,'yy/mm/dd');
						data[i].OldDate = xq.getYMDHM(data[i].OldDate, 'yy/mm/dd');
					}
					_this.trainData = data;
				} else {
					_this.trainData = '';
				}
			})
		},
		//渲染考试倒计时
		daojishi: function() {
			var html = "<div><p>【二级建造师】预计报名</p>day<em>天</em>hours<em>:</em>minutes<em>:</em>seconds</div>"; //d:天 ， h：时，m：分，秒
			var endTime = "2019-02-21";
			$(".djj").daojishi(endTime, html);
		},
		//选择考试分类
		selectTestClass: function(item) {
			this.testClass = item;
			this.getTestInfo();
		},
		//跳到登录页
		toback: function() {
			location.href = xq.loginUrl + '?rebackUrl=' + location.href;
		},
		//选择培训分类
		selectTrainClass: function(item) {
			this.trainClass = item;
			this.getTrainInfo();
		},
		//跳转到增值空间详情页
		toEducationDetail: function(edid) {
			var Url = 'educationDetail.html?id=' + edid;
			window.open(Url,'_blank');
		},

	},
	mounted: function() {
		this.daojishi();
		this.getTestInfo();
		this.getBanner();
		this.getTrainInfo();
		//      xq.confitAnimate();
	},
	updated: function() {

	}
})